package com.sdkj.seckill.rocketmqTest.batchMessage;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 发送不超过4MB的批量消息
 * @Author Jiang
 * @Date 2022/01/19 19:38
 * @Version 1.0.0
 */

public class BatchDemo1 {
    public static void main(String[] args) throws MQBrokerException, RemotingException, InterruptedException, MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("BatchExample");
        producer.setNamesrvAddr("47.98.172.125:9876");
        String topic = "BatchTest";
        List<Message> messages = new ArrayList<>();
        messages.add(new Message(topic,"TagA","OrderID001","Hello world 0".getBytes()));
        messages.add(new Message(topic,"TagA","OrderID002","Hello world 1".getBytes()));
        messages.add(new Message(topic,"TagA","OrderID003","Hello world 2".getBytes()));
        messages.add(new Message(topic,"TagA","OrderID004","Hello world 3".getBytes()));
        //批量发送
        producer.send(messages);

    }

}
